package com.icebergteam.warfacewidget.news.data;

import android.os.Parcel;
import android.os.Parcelable;

import com.icebergteam.warfacewidget.core.ListViewItem;

public class NewsItem extends ListViewItem {

	static public final String className = NewsItem.class.getCanonicalName();
	private int id;
	private String title;
	private String desc;
	private long pubdate;
	private String link;
	private String imgSrc;
	private boolean read; 

	public NewsItem() {
		super();
		this.id = -1;
		this.title = "title test";
		this.desc = "desc test Lorem Ipsum is simply.";
		this.pubdate = 1000000;
		this.link = "link test";
		this.imgSrc = "imgSrc test";
		this.setRead(false);
	}

	public NewsItem(Parcel in) {
		super(in);
	
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public long getPubdate() {
		return pubdate;
	}

	public void setPubdate(long pubdate) {
		this.pubdate = pubdate;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}
	
	/**
	 * @return the m_imgSrc
	 */
	public String getImgSrc() {
		return imgSrc;
	}

	/**
	 * @param m_imgSrc the m_imgSrc to set
	 */
	public void setImgSrc(String m_imgSrc) {
		this.imgSrc = m_imgSrc;
	}

	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeInt(id);
		out.writeString(title);
		out.writeString(desc);
		out.writeLong(pubdate);
		out.writeString(link);
		out.writeString(imgSrc);
		out.writeInt((read)? 1: 0);
	}

	@Override
	public void readFromParcel(Parcel in) {
		this.id = in.readInt();
		this.title = in.readString();
		this.desc = in.readString();
		this.pubdate = in.readLong();
		this.link = in.readString();
		this.imgSrc = in.readString();
		setRead(in.readInt());
	}

	public static final Parcelable.Creator<NewsItem> CREATOR = new Parcelable.Creator<NewsItem>() {
		public NewsItem createFromParcel(Parcel in) {
			return new NewsItem(in);
		}

		public NewsItem[] newArray(int size) {
			return new NewsItem[size];
		}
	};
	
	@Override
	public String toString() {
		return String.format("%s", this == null); //String.format("%s = [%s; %s; %s; %s; %s]", className, m_id, m_title, m_desc, m_pubdate, m_link);
	}
	
	/**
	 * @return the read
	 */
	public boolean isRead() {
		return read;
	}

	/**
	 * @param readed the read to set
	 */
	public void setRead(boolean read) {
		this.read = read;
	}
	
	public void setRead(int read) {
		this.read = (read == 1) ? true: false;
	}
}